﻿using System.ComponentModel;
using MovieDB4.Models;

namespace MovieDB4.ViewModels
{
    class MovieViewModel : INotifyPropertyChanged
    {
        public MovieViewModel(Movie movie)
        {
            this.movie = movie;
        }

        private readonly Movie movie;

        public string Name
        {
            get { return movie.Name; }
            set
            {
                movie.Name = value;
                NotifyPropertyChanged("Name");
            }
        }

        public int Length
        {
            get { return movie.Length; }
            set
            {
                movie.Length = value;
                NotifyPropertyChanged("Length");
            }
        }

        public int Rating
        {
            get { return movie.Rating; }

            set
            {
                if (movie.Rating == value) return;
                movie.Rating = value;
                NotifyPropertyChanged("_Rating");
            }
        }

        public string Path
        {
            get { return movie.Path; }

            set
            {
                if (movie.Path == value) return;
                movie.Path = value;
                NotifyPropertyChanged("Path");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
